import { createRouter, createWebHistory } from "vue-router";
import index from "../views/index/index.vue";
import home from "../views/home/index.vue";
import login from "../views/login/index.vue";
import Layout from "../layout/index.vue";

const routes = [
  {
    path: "/login",
    name: "登录",
    component: login,
  },
  {
    path: "/index",
    name: "网站首页",
    component: index,
    children: [
      {
        path: "/all",
        name: "所有药品",
        component: () => import("../views/index/components/all.vue"),
      },
      {
        path: "/cold",
        name: "感冒药",
        component: () => import("../views/index/components/cold.vue"),
      },
      {
        path: "/stomach",
        name: "肠胃药",
        component: () => import("../views/index/components/stomach.vue"),
      },
      {
        path: "/skin",
        name: "皮肤药",
        component: () => import("../views/index/components/skin.vue"),
      },
      {
        path:"/detail",
        name:'详情',
        component:()=>import("../views/index/components/detail.vue")
      },
      {
        path: "/news",
        name: "新闻咨询",
        component: () => import("../views/index/components/news.vue"),
      },
    ],
  },
  {
    path: "/",
    redirect: "/all",
    meta: {
      requiresAuth: false, //有一些页面是否登录才能进去
      name: "网站首页",
    },
  },
  {
    path: "/main",
    component: Layout,
    name: "main",
    meta: {
      requiresAuth: true, //有一些页面是否登录才能进去
    },
    children: [
      {
        path: "/home",
        name: "主页",
        component: () => import("../views/home/index.vue"),
        meta: {
          requiresAuth: true, //有一些页面是否登录才能进去
        },
      },
      {
        path: "/userhome",
        name: "用户主页",
        component: () => import("../views/userhome/index.vue"),
        meta: {
          requiresAuth: true, //有一些页面是否登录才能进去
        },
      },
      {
        path: "/user",
        name: "个人中心",
        component: () => import("../views/user/index.vue"),
        meta: {
          requiresAuth: true, //有一些页面是否登录才能进去
        },
      },
    ],
  },
  {
    path: "/ErrorMessage",
    name: "异常页面",
    component: Layout,
    children: [
      {
        path: "/404",
        name: "404",
        component: () => import("../views/ErrorMessage/404.vue"),
        meta: {
          requiresAuth: true, //有一些页面是否登录才能进去
          name: "404",
        },
      },
      {
        path: "/500",
        name: "500",
        component: () => import("../views/ErrorMessage/500.vue"),
        meta: {
          requiresAuth: true, //有一些页面是否登录才能进去
          name: "500",
        },
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

export default router;
